<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        #div1{width: 100px;height: 100px;background: red;position: absolute;left: 0;top: 100px;}
    </style>
    <script>
        window.onload = function(){
            var oBtn = document.getElementById("btn1");
            var oDiv = document.getElementById("div1")
            var speed = 5;
            var timer = null;
            oBtn.onclick = function(){
                clearInterval(timer);
                timer = setInterval(function(){
                    if(oDiv.offsetLeft>=500){
                        clearInterval(timer);
                    }else{
                        oDiv.style.left = oDiv.offsetLeft + speed +"px";
                    }
                },30);
            }
        }
    </script>
</head>
<body>
    <button id="btn1">开始运动</button>
    <div id="div1"></div>
</body>
</html>